package edu.mju.serviceutils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 向前端返回的工具类
 */
public class ResponseUtil {
    public static void out(HttpServletResponse httpServletResponse,ResponseCode responseCode){
        ObjectMapper objectMapper = new ObjectMapper();
        //响应头
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        //响应状态码
        httpServletResponse.setStatus(HttpStatus.OK.value());
        try {
            objectMapper.writeValue(httpServletResponse.getWriter(),responseCode);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
